package com.gaara.test;

import android.content.Context;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceHolder.Callback;
import android.view.SurfaceView;

public class MyView extends SurfaceView implements Callback{
	
    private SurfaceHolder sfh;
    private MyThread myThread = new MyThread();
	
    public MyView(Context context) {   
        super(context);   
        
        sfh = this.getHolder();
        sfh.addCallback(this);
        this.setKeepScreenOn(true);//设置背景常亮   
     
        myThread.setSureface(sfh);
        
        init();
    }   

    
    public void init(){
    	MyRes.getInstance().init(this);
    }

    
    public void setScene(IScene scene){
    	myThread.setScene(scene);
    }
    

    
    
	@Override
	public boolean onTouchEvent(MotionEvent event) {
		myThread.onTouchEvent(event);
		return true;
	}


	@Override
	public void surfaceCreated(SurfaceHolder holder) {
		myThread.start();
	}
	
	@Override
	public void surfaceChanged(SurfaceHolder holder, int format, int width,
			int height) {
		MySystem.srceenWidth = width;
		MySystem.srceenHeight = height;
	}

	@Override
	public void surfaceDestroyed(SurfaceHolder holder) {
		// TODO Auto-generated method stub
		
	}  
}
